<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Construct a non-executable tar or zip archive object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phardata.compressfiles.html">« PharData::compressFiles</a></li>
      <li style="float: right;"><a href="phardata.converttodata.html">PharData::convertToData »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phardata.html">PharData</a></li>
    <li>Construct a non-executable tar or zip archive object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phardata.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PharData::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL phar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">PharData::__construct</span> &mdash; <span class="dc-title">Construct a non-executable tar or zip archive object</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-phardata.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PharData::__construct</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$alias</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code><span class="initializer"> = 0</span></span><br>)</div>


 </div>

 <div class="refsect1 parameters" id="refsect1-phardata.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       Path to an existing tar/zip archive or to-be-created archive
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       Flags to pass to <span class="classname"><a href="class.phar.html" class="classname">Phar</a></span> parent class
       <span class="classname"><a href="class.recursivedirectoryiterator.html" class="classname">RecursiveDirectoryIterator</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">alias</code></dt>

     <dd>

      <p class="para">
       Alias with which this Phar archive should be referred to in calls to stream
       functionality.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">format</code></dt>

     <dd>

      <p class="para">
       One of the
       <a href="phar.constants.html#phar.constants.fileformat" class="link">file format constants</a>
       available within the <span class="classname"><a href="class.phar.html" class="classname">Phar</a></span> class.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-phardata.construct-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.badmethodcallexception.html" class="classname">BadMethodCallException</a></span> if called twice;
   <span class="classname"><a href="class.unexpectedvalueexception.html" class="classname">UnexpectedValueException</a></span> if the Phar archive can&#039;t
   be opened.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-phardata.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-768">
    <p><strong>示例 #1 A <span class="function"><strong>PharData::__construct()</strong></span> example</strong></p>
     <div class="example-contents"><p>
      <div class="example-contents">
       <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$p&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PharData</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/my.tar'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">CURRENT_AS_FILEINFO&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">KEY_AS_FILENAME</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">UnexpectedValueException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;open&nbsp;my.tar'</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">BadMethodCallException&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'technically,&nbsp;this&nbsp;cannot&nbsp;happen'</span><span style="color: #007700">;<br />}<br />echo&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar:///path/to/my.tar/example.txt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </p></div>
   </div>
  </p>
 </div>


</div></div></div></body></html>